package com.noc.spring.common.utils;
import java.util.HashMap;
import java.util.Map;

import net.sf.json.JSONObject;

/**
 * 消息处理
 */
public class ResultMessage {
	/**
	 * 成功
	 */
	public static final int Success = 1;

	/**
	 * 其他类型
	 */
	public static final int Other = 2;

	/**
	 * 失败
	 */
	public static final int Fail = 0;

	private int result = 1;
	private String message = "";

	private Map<String, Object> data;

	public ResultMessage() {
	}

	public ResultMessage(int result, String message) {
		this.result = result;
		this.message = message;
	}

	public int getResult() {
		return result;
	}

	public void setResult(int result) {
		this.result = result;
	}

	public String getMessage() {
		return message;
	}

	public void setMessage(String message) {
		this.message = message;
	}

	/**
	 * 结果是否成功
	 * 
	 * @return
	 */
	@SuppressWarnings("static-access")
	public boolean isSuccess() {
		return this.result == this.Success;
	}

	public ResultMessage(int result, String message, Map<String, Object> data) {
		this.result = result;
		this.message = message;
		this.data = data;
	}

	public String toString() {
		Map<String, Object> resultMap = new HashMap<String, Object>();
		resultMap.put("result", result);
		resultMap.put("message", message);
		resultMap.put("data", data);
		return JSONObject.fromObject(resultMap).toString();
	}
}
